<script setup lang="ts">
import { useWebInfoStore } from "@/store/modules/webInfo"
import { useSettingsStore } from "@/store/modules/settings"
import TimeCard from "./TimeCard.vue"
import Battery from "./Battery.vue"

// 前台信息仓库
const webInfoStore = useWebInfoStore()

const settingsStore = useSettingsStore()
// 点击打开弹框预览
const openPreview = (tag:any) => {
  if (!settingsStore.isMobile) {
    webInfoStore.openPreview(tag)
  }
}
</script>
<template>
  <!-- 主用户卡片 -->
  <div class="modern-user-card mb-6">
    <div class="user-card-content">
      <!-- 背景装饰 -->
      <div class="card-bg-decoration"></div>

      <!-- 用户头像 -->
      <div class="avatar-container" @click="$router.push('/home-userInfo')">
        <div class="avatar-ring">
          <el-avatar :src="webInfoStore.authorInfo?.avatar" :size="80" />
        </div>
        <div class="avatar-status"></div>
      </div>

      <!-- 用户信息 -->
      <div class="user-info">
        <h3 class="user-name">
        {{ webInfoStore.authorInfo?.nickname }}
          <SvgIcon
            :name="webInfoStore.authorInfo?.gender === 1 ? 'boy' : 'girl'"
            class="gender-icon"
          />
        </h3>
        <p class="user-intro">{{ webInfoStore.authorInfo?.introduction }}</p>
          </div>

      <!-- 社交链接 -->
      <div class="social-links">
        <a
          v-if="webInfoStore.authorInfo?.github"
          :href="webInfoStore.authorInfo?.github"
          target="_blank"
          class="social-link github"
          title="GitHub"
        >
          <SvgIcon name="github" />
        </a>
        <a
          v-if="webInfoStore.authorInfo?.csdn"
          :href="webInfoStore.authorInfo?.csdn"
          target="_blank"
          class="social-link csdn"
          title="CSDN"
        >
          <SvgIcon name="csdn" />
        </a>
        <a
          v-if="webInfoStore.authorInfo?.gitee"
          :href="webInfoStore.authorInfo?.gitee"
          target="_blank"
          class="social-link gitee"
          title="Gitee"
        >
          <SvgIcon name="gitee" />
        </a>
      </div>
    </div>
  </div>

  <!-- 电量显示 -->
  <Battery v-if="!settingsStore.isMobile" class="mb-4" />

  <!-- 时间面板 -->
  <TimeCard class="mb-4" />

  <!-- 标签卡片 -->
  <div class="modern-tags-card">
    <div class="tags-header">
      <div class="tags-title">
        <div class="title-icon">
          <SvgIcon name="tags" />
        </div>
        <h4>热门标签</h4>
      </div>
    </div>

    <div class="tags-content">
      <div
        v-for="item in webInfoStore.tagInfo?.slice(0, 8)"
        :key="item._id"
        class="modern-tag-item"
        @click.stop="openPreview(item)"
      >
        <el-image class="tag-icon" :src="item.icon" fit="fill" />
        <span class="tag-text">{{ item.name }}</span>
      </div>
      <div v-if="webInfoStore.tagInfo?.length > 8" class="more-tags-indicator">
        +{{ webInfoStore.tagInfo.length - 8 }} 更多
      </div>
    </div>
  </div>
</template>

<style scoped lang="scss">
// 现代化用户卡片
.modern-user-card {
  background: white;
  border-radius: 25px;
  overflow: hidden;
  box-shadow:
    0 15px 35px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  position: relative;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);

  &:hover {
    transform: translateY(-5px);
    box-shadow:
      0 25px 50px rgba(0, 0, 0, 0.15),
      0 0 0 1px rgba(102, 126, 234, 0.2);
  }

  .dark & {
    background: #1f2937;
    border-color: #374151;
  }
}

.user-card-content {
  padding: 30px;
  text-align: center;
  position: relative;
  z-index: 2;
}

// 背景装饰
.card-bg-decoration {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: var(--gradient-primary);

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
      radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.2) 0%, transparent 50%),
      radial-gradient(circle at 70% 70%, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
  }
}

// 头像容器
.avatar-container {
  position: relative;
  display: inline-block;
  margin-bottom: 20px;
  cursor: pointer;

  .avatar-ring {
    position: relative;
    padding: 4px;
    background: var(--gradient-primary);
    border-radius: 50%;
    transition: all 0.3s ease;

    &::before {
      content: '';
      position: absolute;
      inset: -3px;
      background: var(--gradient-primary);
      border-radius: 50%;
      opacity: 0;
      transition: opacity 0.3s ease;
      z-index: -1;
    }

    :deep(.el-avatar) {
      border: 3px solid white;
      box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }
  }

  .avatar-status {
    position: absolute;
    bottom: 5px;
    right: 5px;
    width: 20px;
    height: 20px;
    background: #10b981;
    border: 3px solid white;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(16, 185, 129, 0.3);
  }

  &:hover .avatar-ring {
    transform: scale(1.05);

    &::before {
      opacity: 0.3;
    }
  }
}

// 用户信息
.user-info {
  margin-bottom: 25px;

  .user-name {
    font-size: 22px;
    font-weight: 700;
    color: #1a202c;
    margin-bottom: 8px;
  display: flex;
  align-items: center;
    justify-content: center;
    gap: 8px;

    .gender-icon {
      width: 20px;
      height: 20px;
    }

    .dark & {
      color: white;
    }
  }

  .user-intro {
    color: #64748b;
    font-size: 14px;
    line-height: 1.6;
    max-width: 250px;
    margin: 0 auto;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;

    .dark & {
      color: #9ca3af;
    }
  }
}

// 社交链接
.social-links {
  display: flex;
  justify-content: center;
  gap: 15px;

  .social-link {
    width: 45px;
    height: 45px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;

    :deep(svg) {
      width: 22px;
      height: 22px;
      z-index: 2;
      position: relative;
    }

    &::before {
      content: '';
      position: absolute;
      inset: 0;
      border-radius: 15px;
      opacity: 0.1;
      transition: all 0.3s ease;
    }

    &:hover {
      transform: translateY(-3px);

      &::before {
        opacity: 0.2;
      }
    }

    &.github {
      background: rgba(36, 41, 46, 0.1);
      color: #24292e;

      &::before {
        background: #24292e;
      }

      &:hover {
        box-shadow: 0 8px 25px rgba(36, 41, 46, 0.3);
      }
    }

    &.csdn {
      background: rgba(252, 107, 3, 0.1);
      color: #fc6b03;

      &::before {
        background: #fc6b03;
      }

      &:hover {
        box-shadow: 0 8px 25px rgba(252, 107, 3, 0.3);
      }
    }

    &.gitee {
      background: rgba(196, 26, 22, 0.1);
      color: #c41a16;

      &::before {
        background: #c41a16;
      }

      &:hover {
        box-shadow: 0 8px 25px rgba(196, 26, 22, 0.3);
      }
    }
  }
}

// 现代化标签卡片
.modern-tags-card {
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow:
    0 10px 30px rgba(0, 0, 0, 0.1),
    0 0 0 1px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;

  &:hover {
    box-shadow:
      0 15px 40px rgba(0, 0, 0, 0.15),
      0 0 0 1px rgba(102, 126, 234, 0.2);
  }

  .dark & {
    background: #1f2937;
    border-color: #374151;
  }
}

.tags-header {
  background: var(--gradient-primary);
  padding: 20px 25px;
  position: relative;

  &::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
      radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
      radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.05) 0%, transparent 50%);
    pointer-events: none;
  }

  .tags-title {
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    z-index: 1;

    .title-icon {
      width: 40px;
      height: 40px;
      background: rgba(255, 255, 255, 0.2);
      border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
      backdrop-filter: blur(10px);

      :deep(svg) {
        width: 20px;
        height: 20px;
        color: white;
      }
    }

    h4 {
      color: white;
      font-size: 18px;
      font-weight: 700;
      margin: 0;
      text-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    }
  }
}

.tags-content {
  padding: 25px;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.modern-tag-item {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, #f8fafc, #e2e8f0);
  border: 1px solid rgba(102, 126, 234, 0.1);
  border-radius: 25px;
  padding: 8px 16px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;

  &::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--gradient-primary);
    opacity: 0;
    transition: opacity 0.3s ease;
  }

  .tag-icon {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    position: relative;
    z-index: 2;
  }

  .tag-text {
    font-size: 13px;
    font-weight: 500;
    color: #475569;
    position: relative;
    z-index: 2;
    transition: color 0.3s ease;
  }

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.3);

    &::before {
      opacity: 1;
    }

    .tag-text {
      color: white;
    }
  }

  .dark & {
    background: #374151;
    border-color: #4b5563;

    .tag-text {
      color: #d1d5db;
    }
  }
}

.more-tags-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 600;
  border: 1px dashed #667eea;
}

// 响应式设计
@media (max-width: 768px) {
  .user-card-content {
    padding: 25px 20px;
  }

  .social-links {
    gap: 12px;

    .social-link {
      width: 40px;
      height: 40px;

      :deep(svg) {
        width: 18px;
        height: 18px;
      }
    }
  }

  .tags-content {
    padding: 20px;
    gap: 10px;
  }

  .modern-tag-item {
    font-size: 12px;
    padding: 6px 12px;
  }
}

// 光标样式
.avatar-container,
.social-link,
.modern-tag-item {
  cursor: var(--cursor-pointer, pointer);
}
</style>
